//
//  HbottomView.swift
//  GZWeibo007
//
//  Created by 何梓杰 on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit
import SVProgressHUD

protocol HbottomViewDelegate: NSObjectProtocol {
    

    // 协议里面默认是必须实现的
    // 评论按钮被点击
    func commentClick()
    
    // 转发按钮被点击
    func forwardClick()
    
    // 点赞、
    func goodClick()
}
class HbottomView: UIView {
    
   
    
    weak var delegate: HbottomViewDelegate?
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.9, alpha: 1)
        // 准备UI
        prepareUI()
    }
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func prepareUI() {
        //添加子控件
        addSubview(commentButton)
        addSubview(forwardButton)
        addSubview(goodButton)
        
        //添加约束
        self.ff_HorizontalTile([commentButton, forwardButton, goodButton], insets: UIEdgeInsetsZero)
        
        //分割线的约束
        separatorViewFirst.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: commentButton, size: nil)
        
        separatorViewSecond.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: forwardButton, size: nil)
        
        //添加点击事件
        commentButton.addTarget(self, action: "sentComment", forControlEvents: UIControlEvents.TouchUpInside)
        
        forwardButton.addTarget(self, action: "sentForward", forControlEvents: UIControlEvents.TouchUpInside)
        
        goodButton.addTarget(self, action: "sentGood", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    // MARK: - 懒加载控件
    // 转发
    private lazy var forwardButton: UIButton = UIButton(imageName: "timeline_icon_retweet", fontSize: 11, title: "转发")
    
    // 评论
    private lazy var commentButton: UIButton = UIButton(imageName: "timeline_icon_comment", fontSize: 11, title: "评论")
    
    // 赞
    private lazy var goodButton: UIButton = UIButton(imageName: "timeline_icon_unlike", fontSize: 11, title: "赞")
    
    // 分割线1
    private lazy var separatorViewFirst: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
    // 分割线1
    private lazy var separatorViewSecond: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    
    
    //点击事件
    
    func sentComment() {
        
        delegate?.commentClick()
    }
    
    func sentForward() {
        
        delegate?.forwardClick()
    }
    
    func sentGood() {
        
        delegate?.goodClick()
    }
    
}
